package org.sheep;

import org.sheep.sprite.Bullet;
import org.sheep.sprite.LaneManager;

import java.lang.System;

public class Spawn {
  private Bullet dummy;
  private int lane;
  private int amount;
  private int delay;
  private int speed;
  private int rand;
  
  private long startTime;
  private int turn = 1;
  private double cRand;
  private long lastTime;
  
  public Spawn(Bullet dummy, int lane, int amount, int delay,
               int speed, int rand, LaneManager lm) {
    this.dummy = dummy;
    this.lane = lane;
    this.amount = amount;
    this.delay = delay;
    this.speed = speed;
    this.rand = rand;
    manager = lm;
  }
  
  public void start() {
    startTime = System.currentTimeMillis()+delay;
    cRand =  Math.random() * rand;
    lastTime = startTime;
  }
  
  public boolean spawn() {
    long time = System.currentTimeMillis();

    if(time > startTime+delay) {
      if(time-lastTime > speed+cRand) {
        turn++;
        manager.spawnEnemy(lane, dummy.clone());
        cRand =  Math.random() * rand;
        lastTime = time;
      }
    }

    return turn < amount;
  }
}